#! /usr/bin/env node
// chmod 755 cli.js
const path = require('path')
const inquirer = require('inquirer')
const fs = require('fs')
const ejs = require('ejs')
inquirer.prompt([
  {
    type: 'input',
    name: 'name',
    message: 'Project name?'
  }
])
.then(anwsers => {
    console.log(anwsers)
    // 模版目录
    const tmplDir = path.join(__dirname, 'templates')
    // 输出目录
    const destDir = process.cwd()
    // 获取模版目录下的所有文件
    fs.readdir(tmplDir, (err, files) => {
      if (err) throw err
      files.forEach(file => {
        console.log(file)
        ejs.renderFile(path.join(tmplDir, file), anwsers, (err, result) => {
          if (err) throw err
          fs.writeFileSync(path.join(destDir, file), result)
        })
      })
    })
})
